<?php
namespace App\Api\Controllers\Vbill;


use function EasyWeChat\Kernel\Support\get_client_ip;
use function EasyWeChat\Kernel\Support\get_server_ip;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;

class PayController extends BaseController
{
    //扫一扫 0-系统错误 1-成功 2-正在支付 3-失败
    public function scan_pay($data)
    {
        try {
            $out_trade_no = $data['out_trade_no'];
            $code = $data['code'];
            $total_amount = $data['total_amount'];
            $remark = $data['remark'];
            $device_id = $data['device_id'];
            $shop_name = $data['shop_name'];
            $notify_url = $data['notify_url'];
            $url = $data['request_url'];
            $payType = $data['pay_type'];
            $mno = $data['mno'];
            $orgId = $data['orgId'];
            $privateKey = $data['privateKey'];
            $sxfpublic = $data['sxfpublic'];
            $total_amount = number_format($total_amount, 2, '.', '');

            $obj = new BaseController();
            $data_re = [
                'orgId' => $orgId,
                'reqId' => time(),
                'version' => '1.0',
                'timestamp' => date('Ymdhis', time()),
                'signType' => 'RSA',
                'reqData' => [
                    'mno' => $mno,//商户编号
                    'ordNo' => $out_trade_no,//商户订单号
                    'scene' => '1',
                    'authCode' => $code,
                    'amt' => $total_amount,//订单总金额元
                    'payType' => $payType,//
                    'subject' => $shop_name,//订单标题
                    'tradeSource' => '01',
                    'trmIp' => get_client_ip(),
                    'notifyUrl' => $notify_url
                ],
            ];

            //单品
            $isGoods = 2;
            if (isset($data['store_id']) && !empty($data['store_id'])) {
                $isGoods =  \App\Models\Store::where('store_id', $data['store_id'])->value('is_goods');   
            }
            if (isset($data['goods_detail']) && !empty($data['goods_detail'])) {
                  error_log(date('Y-m-d H:i:s')." 【随行付单品】： ".$out_trade_no."参数：".json_encode([$data['goods_detail'], $isGoods])."\n\n", 3, "/www/wwwlogs/wft/". 'prod-vbill'.date('Ymd').".log");
            }
           
            if (isset($data['goods_detail']) && !empty($data['goods_detail']) && $isGoods == 1) {
                $goods = json_decode($data['goods_detail'], true);
                $goodsArr = [];
                foreach ($goods['goods_detail'] as $v) {
                    $price = $v['price'] * 0.01;
                    $goodsArr[] = [
                        'quantity'  => $v['quantity'],
                        'goodsId'   => $v['goods_id'],
                        'price'     => sprintf("%.2f", $price),
                        'goodsName' => $v['goods_name'],
                    ];
                }
                ksort($goodsArr);
                $data_re['reqData']['goodsTag'] = '00';
                $costPrice = $goods['cost_price'] * 0.01;
                $costPrice = number_format($costPrice, 2, '.', '');
                $data_re['reqData']['couponDetail'] = json_encode([
                    'costPrice'   => $costPrice,
                    'receiptId'   => $goods['receipt_id'],
                    'goodsDetail' => $goodsArr,
                ]);
            }
            

            if ($payType=="WECHAT"&&isset($data['subAppid'])) {
                $data_re['reqData']['subAppid'] = $data['subAppid'];
            }
            // error_log(date('Y-m-d H:i:s')." 【随行付入参】： ".json_encode($data_re)."\n\n", 3, "/tmp/". 'vbill'.date('Ymd').".log");
//            error_log(date('Y-m-d H:i:s')." 【随行付入参】： ".json_encode($data_re)."\n\n", 3, "/www/wwwlogs/wft/". 'prod-vbill'.date('Ymd').".log");
            Log::channel('vbill')->info(date('Y-m-d H:i:s')." vbill-pay-req-".$out_trade_no."： ", $data_re);
            $re = $obj->execute($data_re, $url, $privateKey, $sxfpublic);
//            error_log(date('Y-m-d H:i:s')." 【随行付响应】： ".json_encode($re)."\n\n", 3, "/www/wwwlogs/wft/". 'prod-vbill'.date('Ymd').".log");
            Log::channel('vbill')->info(date('Y-m-d H:i:s')." vbill-pay-res-".$out_trade_no.": ", [$re]);
            //  error_log(date('Y-m-d H:i:s')." 【随行付响应】： ".json_encode($re)."\n\n", 3, "/tmp/". 'vbill'.date('Ymd').".log");

            // Log::info($re);

            //系统错误
            if ($re['status'] == 0) {
                return $re;
            }

            //业务成功
            if ($re['data']['code'] == "0000") {
                //交易成功
                if ($re['data']['respData']['bizCode'] == "0000") {
                    \App\Common\PaySuccessAction::addCoupon($out_trade_no, $re['data'], 'pay');
                    return [
                        'status' => 1,
                        'message' => '交易成功',
                        'data' => $re['data'],
                    ];
                } //用户输入密码
                elseif ($re['data']['respData']['bizCode'] == "2002") {
                    return [
                        'status' => 2,
                        'message' => '请用户输入密码',
                        'data' => $re['data'],
                    ];
                } else {
                    return [
                        'status' => 3,
                        'message' => $re['data']['respData']['bizMsg'],
                        'data' => $re['data'],
                    ];
                }
            } else {
                return [
                    'status' => 0,
                    'message' => $re['data']['msg']
                ];
            }

        } catch (\Exception $ex) {
            return [
                'status' => '0',
                'message' => $ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine(),
            ];
        }
    }


    //查询订单 0-系统错误 1-成功 2-正在支付 3-失败 4.已经退款
    public function order_query($data)
    {
        try {
            $out_trade_no = $data['out_trade_no'];
            $url = $data['request_url'];
            $mno = $data['mno'];
            $orgId = $data['orgId'];
            $privateKey = $data['privateKey'];
            $sxfpublic = $data['sxfpublic'];

            $obj = new BaseController();
            $data = [
                'orgId' => $orgId,
                'reqId' => time(),
                'version' => '1.0',
                'timestamp' => date('Ymdhis', time()),
                'signType' => 'RSA',
                'reqData' => [
                    'mno' => $mno,//商户编号
                    'ordNo' => $out_trade_no,//商户订单号
                ],
            ];
             //error_log(date('Y-m-d H:i:s')." 【随行付入参1】： ".json_encode($data)."\n\n", 3, "/tmp/". 'vbill'.date('Ymd').".log");

            $re = $obj->execute($data, $url, $privateKey, $sxfpublic);
            //file_put_contents('vbill-query.log',var_export($re,true)."\r\n",FILE_APPEND);
            // error_log(date('Y-m-d H:i:s')." 【随行付入参2】： ".json_encode($re)."\n\n", 3, "/tmp/". 'vbill'.date('Ymd').".log");
            Log::channel('vbill')->info("vbill-query-api-res-".$out_trade_no, [
                "req"=>$data,
                "res"=>$re
            ]);
            //系统错误
            if ($re['status'] == 0) {
                return $re;
            }
            //业务成功
            if ($re['data']['code'] == "0000") {
                //交易成功
                if ($re['data']['respData']['tranSts'] == "SUCCESS") {
                    \App\Common\PaySuccessAction::addCoupon($out_trade_no, $re['data'], 'query');
                    return [
                        'status' => 1,
                        'message' => '交易成功',
                        'data' => $re['data'],
                    ];
                } //用户输入密码
                elseif ($re['data']['respData']['tranSts'] == "PAYING") {
                    return [
                        'status' => 2,
                        'message' => '请用户输入密码',
                        'data' => $re['data'],
                    ];
                    //用户取消
                } elseif ($re['data']['respData']['tranSts'] == "NOTPAY") {
                    return [
                        'status' => 3,
                        'message' => $re['data']['respData']['bizMsg'],
                        'data' => $re['data'],
                    ];
                } else {
                    return [
                        'status' => 3,
                        'message' => $re['data']['respData']['bizMsg'],
                        'data' => $re['data'],
                    ];
                }


            } else {
                return [
                    'status' => 0,
                    'message' => $re['data']['msg']
                ];
            }

        } catch (\Exception $ex) {
            return [
                'status' => '0',
                'message' => $ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine(),
            ];
        }
    }
    
    
    //付款码交换openid
    public function getSubOPenid($data){
        try {
            // $out_trade_no = $data['out_trade_no'];
            $url = $data['request_url'];
            $mno = $data['mno'];
            // $orgId = $data['orgId'];
            $privateKey = $data['privateKey'];
            $sxfpublic = $data['sxfpublic'];
            $obj = new BaseController();
            $data = [
                'orgId' => '89229697',
                'reqId' => time(),
                'version' => '1.0',
                'timestamp' => date('Ymdhis', time()),
                'signType' => 'RSA',
                'reqData' => [
                    'mno' => $mno,//商户编号
                    'subMchId' => $data['subMchId'],//子商户号
                    'subAppId' => $data['subAppId'],//商户订单号
                    'authCode' => $data['authCode'],//商户订单号
                ],
            ];
            $re = $obj->execute($data, $url, $privateKey, $sxfpublic);
            return [
                'status' => 1,
                'message' => '请求成功',
                'data' => $re['data'],
            ];
        } catch (\Exception $ex) {
            return [
                'status' => '0',
                'message' => $ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine(),
            ];
        }
    }


    //退款 0-系统错误 1-成功
    public function refund($data)
    {
        try {
            $out_trade_no = $data['out_trade_no'];
            $url = $data['request_url'];
            $mno = $data['mno'];
            $orgId = $data['orgId'];
            $privateKey = $data['privateKey'];
            $sxfpublic = $data['sxfpublic'];
            $refund_amount = $data['refund_amount'];
            $refund_notify_url = $data['notify_url'];
            $ordNo = $out_trade_no . rand(1000, 9999);

            $obj = new BaseController();
            $data = [
                'orgId' => $orgId,
                'reqId' => time(),
                'version' => '1.0',
                'timestamp' => date('Ymdhis', time()),
                'signType' => 'RSA',
                'reqData' => [
                    'ordNo' => $ordNo,
                    'mno' => $mno, //商户编号
                    'origOrderNo' => $out_trade_no, //商户订单号
                    'amt' => $refund_amount,
                    'notifyUrl' => $refund_notify_url
                ],
            ];
            $this->add_refund_orders($ordNo,$out_trade_no,$refund_amount);
            $re = $obj->execute($data, $url, $privateKey, $sxfpublic);

            //系统错误
            if ($re['status'] == 0) {
                return $re;
            }
            //业务成功
            if ($re['data']['code'] == "0000") {
                //退款成功
                if ($re['data']['respData']['bizCode'] == "0000" && isset($re['data']['respData']['tranSts']) && $re['data']['respData']['tranSts']=="REFUNDSUC") {
                    //
                    \App\Common\PaySuccessAction::addCoupon($out_trade_no, '', 'refund');
                    return [
                            'status' => 1,
                            'message' => '退款成功',
                            'data' => $re['data'],
                    ];
                } else {
			        sleep(3); //5秒后在发起查询
                    //退款失败，查询退款结果
                    $url = $this->refund_query_url;
                    $data = [
                        'orgId' => $orgId,
                        'reqId' => time(),
                        'version' => '1.0',
                        'timestamp' => date('Ymdhis', time()),
                        'signType' => 'RSA',
                        'reqData' => [
                            'ordNo' => $ordNo,
                            'mno' => $mno, //商户编号
                        ],
                    ];
                    $re = $obj->execute($data, $url, $privateKey, $sxfpublic);

                    if ($re['data']['code'] == "0000") {
                        if ($re['data']['respData']['bizCode'] == "0000") {
                            if ($re['data']['respData']['tranSts']=="REFUNDSUC") {
                                \App\Common\PaySuccessAction::addCoupon($out_trade_no, '', 'refund');
                                return [
                                    'status' => 1,
                                    'message' => '退款成功',
                                    'data' => $re['data'],
                                ];
                            }

                            if ($re['data']['respData']['tranSts'] == "REFUNDING") {
                                return [
                                    'status' => 2,
                                    'message' => '退款中',
                                    'data' => $re['data'],
                                ];
                            }
                        }


                        if ($re['data']['respData']['bizCode'] == "2002") {
                            return [
                                'status' => 1,
                                'message' => '退款成功',
                                'data' => $re['data'],
                            ];
                        }

                    }

                    return [
                        'status' => 0,
                        'message' => $re['data']['respData']['bizMsg'],
                        'data' => $re['data'],
                    ];
                }
            } else {
                return [
                    'status' => 0,
                    'message' => $re['data']['msg']
                ];
            }

        } catch (\Exception $ex) {
            return [
                'status' => 0,
                'message' => $ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine()
            ];
        }
    }


    //退款查询 0-系统错误 1-成功 2-正在退款 3-失败
    public function refund_query($data)
    {
        try {
            $out_trade_no = $data['out_trade_no']; //系统订单号
            $url = $data['request_url']; //退款查询结果地址
            $mno = $data['mno']; //商户编号
            $orgId = $data['orgId']; //随行付机构号
            $privateKey = $data['privateKey']; //平台私钥
            $sxfpublic = $data['sxfpublic']; //随行付公钥

            $obj = new BaseController();
            $url = $this->refund_query_url;
            $data = [
                'orgId' => $orgId,
                'reqId' => time(),
                'version' => '1.0',
                'timestamp' => date('Ymdhis', time()),
                'signType' => 'RSA',
                'reqData' => [
                    'ordNo' => $out_trade_no, //商户退款订单号
//                    'ordNo' => $out_trade_no . '123', //商户退款订单号
                    'mno' => $mno, //商户入驻返回的商户编号
                ],
            ];
            Log::info('随行付-退款查询');
            Log::info($data);
            $re = $obj->execute($data, $url, $privateKey, $sxfpublic);
//            Log::info('随行付退款查询请求原始结果');
//            Log::info($re);

            //系统错误
            if ($re['status'] == 0) {
                return $re;
            }
            //业务成功
            if ($re['data']['code'] == "0000") {
                //退款成功
                if ($re['data']['respData']['tranSts'] == "REFUNDSUC") {
                    return [
                        'status' => 1,
                        'message' => '退款成功',
                        'data' => $re['data'],
                    ];
                } elseif ($re['data']['respData']['tranSts'] == 'REFUNDING') {
                    return [
                        'status' => 2,
                        'message' => '正在退款中',
                        'data' => $re['data'],
                    ];
                } elseif ($re['data']['respData']['tranSts'] == 'REFUNDFAIL') {
                    return [
                        'status' => 2,
                        'message' => '退款失败',
                        'data' => $re['data'],
                    ];
                } else {
                    return [
                        'status' => 0,
                        'message' => $re['data']['respData']['bizMsg'],
                        'data' => $re['data'],
                    ];
                }

            } else {
                return [
                    'status' => 0,
                    'message' => $re['data']['msg']
                ];
            }


        } catch (\Exception $ex) {
            return [
                'status' => '0',
                'message' => $ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine()
            ];
        }
    }


    //生成动态二维码-公共
    public function send_qr($data)
    {
        try {
            $out_trade_no = $data['out_trade_no'];
            $total_amount = $data['total_amount'];
            $remark = $data['remark'];
            $notify_url = $data['notify_url'];
            $url = $data['request_url'];
            $merchant_no = $data['merchant_no'];
            $returnParams = $data['return_params'];//原样返回
            $des_key = $data['des_key'];
            $md_key = $data['md_key'];
            $systemId = $data['systemId'];
            //请求数据
            $data = [
                'merchantNo' => $merchant_no,
                'businessCode' => 'AGGRE',
                'version' => '3.0',
                'outTradeNo' => $out_trade_no,
                'amount' => $total_amount * 100,
                'remark' => $remark,//
                'returnParams' => $returnParams,
                'businessType' => '00',//返回二维码
                'successNotifyUrl' => $notify_url,
            ];

            $obj = new BaseController();
            $obj->des_key = $des_key;
            $obj->md_key = $md_key;
            $obj->systemId = $systemId;
//            Log::info('随行付-生成动态二维码');
//            Log::info($data);
            $re = $obj->execute($data, $url);
//            Log::info($re);

            //系统错误
            if ($re['status'] == 0) {
                return $re;
            }

            //业务成功
            if ($re['data']['resultCode'] == "SUCCESS") {
                return [
                    'status' => 1,
                    'message' => '返回成功',
                    'code_url' => $re['data']['scanUrl'],
                    'data' => $re['data']
                ];
            } else {
                return [
                    'status' => 0,
                    'message' => $re['data']['errCodeDes']
                ];
            }
        } catch (\Exception $ex) {
            return [
                'status' => '0',
                'message' => $ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine()
            ];
        }
    }


    //静态码提交-公共
        public function qr_submit($data)
    {
        try {
            $out_trade_no = $data['out_trade_no'];
            $total_amount = $data['total_amount'];
            $remark = $data['remark'];
            $device_id = $data['device_id'];
            $shop_name = $data['shop_name'];
            $notify_url = $data['notify_url'];
            $url = $data['request_url'];
            $payType = $data['pay_type'];
            $payWay = $data['pay_way'];
            $mno = $data['mno'];
            $orgId = $data['orgId'];
            $privateKey = $data['privateKey'];
            $sxfpublic = $data['sxfpublic'];
            $open_id = $data['open_id'];

            $reqData = [
                'mno' => $mno,//商户编号
                'ordNo' => $out_trade_no,//商户订单号
                'amt' => $total_amount,//订单总金额元
                'payType' => $payType,//
                'payWay' => $payWay,
                'subject' => $shop_name,//订单标题
                'tradeSource' => '01',
                'trmIp' => get_client_ip(),
                'notifyUrl' => $notify_url,
                'userId'=>$open_id,
                "returnUrl"=>$data["returnUrl"]??""
            ];
            
            
            //单品
            $isGoods = 2;
            if (isset($data['store_id']) && !empty($data['store_id'])) {
                $isGoods =  \App\Models\Store::where('store_id', $data['store_id'])->value('is_goods');
            }
            $data['goods_detail'] = $couponDetail = '';
            if (!empty(request('goods'))) {
                $goods=json_decode(request('goods'), true);
                unset($data['goods']);
                $goods_detail=array();
                foreach($goods as $k=>$v){
                    $goods_detail[$k]['goods_name']=$v['goods_name'];
                    $goods_detail[$k]['quantity']=intval($v['count']);
                    $goods_detail[$k]['price']=bcmul((string)$v['goods_price'],"100");
                    $goods_detail[$k]['goods_id']=$v['goods_code'];
                }
                $Detail['receipt_id']=time();
                $Detail['goods_detail']=$goods_detail;
                $Detail['cost_price']=bcmul((string)$data['total_amount'],"100");
                $couponDetail = json_encode($Detail,JSON_UNESCAPED_UNICODE);
            }

            if (!empty($couponDetail) && $isGoods == 1) {
                $goods = json_decode($couponDetail, true);
                $goodsArr = [];
                foreach ($goods['goods_detail'] as $v) {
                    $price = $v['price'] * 0.01;
                    $goodsArr[] = [
                        'quantity'  => $v['quantity'],
                        'goodsId'   => $v['goods_id'],
                        'price'     => sprintf("%.2f", $price),
                        'goodsName' => $v['goods_name'],
                    ];
                }
                ksort($goodsArr);
                $costPrice = $goods['cost_price'] * 0.01;
                $costPrice = number_format($costPrice, 2, '.', '');
                $couponDetail = json_encode([
                    'costPrice'   => $costPrice,
                    'receiptId'   => $goods['receipt_id'],
                    'goodsDetail' => $goodsArr,
                ]);
                $reqData['goodsTag'] = '00';
                $reqData['couponDetail'] = $couponDetail;
            }
            //单品

            if (isset($data['subAppid'])) {
                $reqData['subAppid'] = $data['subAppid'];
            }

            if ($payType == "UNIONPAY") {
                $reqData['customerIp'] = get_client_ip();
            }

            $obj = new BaseController();
            $data = [
                'orgId' => $orgId,
                'reqId' => time(),
                'version' => '1.0',
                'timestamp' => date('Ymdhis', time()),
                'signType' => 'RSA',
                'reqData' => $reqData,
            ];
            $re = $obj->execute($data, $url, $privateKey, $sxfpublic);
            Log::channel("vbill")->info("vbill_qr_submit",[
                "req"=>$data,
                "url"=>$url,
                "res"=>$re
            ]);
            //系统错误
            if ($re['status'] == 0) {
                return $re;
            }

            //业务成功
            if ($re['data']['code'] == "0000") {
                //交易成功
                if ($re['data']['respData']['bizCode'] == "0000") {
                    return [
                        'status' => 1,
                        'message' => '交易成功',
                        'data' => $re['data'],
                    ];
                } //用户输入密码
                elseif ($re['data']['respData']['bizCode'] == "2002") {
                    return [
                        'status' => 2,
                        'message' => '请用户输入密码',
                        'data' => $re['data'],
                    ];
                } else {
                    return [
                        'status' => 3,
                        'message' => $re['data']['respData']['bizMsg'],
                        'data' => $re['data'],
                    ];
                }


            } else {
                return [
                    'status' => 0,
                    'message' => $re['data']['msg']
                ];
            }
        } catch (\Exception $ex) {
            Log::channel("vbill")->info("error",[
                "error"=>$ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine(),
                "data"=>$data
            ]);
            return [
                'status' => '0',
                'message' => "系统异常，请联系管理员",//$ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine()
            ];
        }
    }
    
    
     //获取银联标志
    public function get_un_openid($data)
    {
        try {
            $url = 'https://openapi.tianquetech.com/query/getUnionInfo';
            $userAuthCode = $data['userAuthCode'];
            $paymentApp = $data['paymentApp'];
            $orgId = $data['orgId'];
            $privateKey = $data['privateKey'];
            $sxfpublic = $data['sxfpublic'];

            $reqData = [
                'userAuthCode' => $userAuthCode,//授权码
                'paymentApp' => $paymentApp,//订单总金额元
            ];

            $obj = new BaseController();
            $data = [
                'orgId' => $orgId,
                'reqId' => time(),
                'version' => '1.0',
                'timestamp' => date('Ymdhis', time()),
                'signType' => 'RSA',
                'reqData' => $reqData,
            ];

            $re = $obj->execute($data, $url, $privateKey, $sxfpublic);
             error_log(date('Y-m-d H:i:s')." 【获取银联标志】： ".json_encode($re)."\n\n", 3, "/tmp/". 'get_un_openid'.date('Ymd').".log");

            if ($re['status'] == 0) {
                return $re;
            }

            //业务成功
            if ($re['data']['code'] == "0000") {
                //交易成功
                if ($re['data']['respData']['bizCode'] == "0000") {
                    return [
                        'status' => 1,
                        'message' => '交易成功',
                        'data' => $re['data'],
                    ];
                } //用户输入密码
                elseif ($re['data']['respData']['bizCode'] == "2002") {
                    return [
                        'status' => 2,
                        'message' => '请用户输入密码',
                        'data' => $re['data'],
                    ];
                } else {
                    return [
                        'status' => 3,
                        'message' => $re['data']['respData']['bizMsg'],
                        'data' => $re['data'],
                    ];
                }
            } else {
                return [
                    'status' => 0,
                    'message' => $re['data']['msg']
                ];
            }
        } catch
        (\Exception $exception) {
            return [
                'status' => 0,
                'message' => $exception->getMessage(),
            ];
        }
    }


    //获取微信刷脸调用凭证
    public function lose_face($data)
    {
        try {
            $out_trade_no = $data['out_trade_no'];
            $url = $data['url'];
            $mno = $data['mno'];
            $orgId = $data['orgId'];
            $privateKey = $data['privateKey'];
            $sxfpublic = $data['sxfpublic'];
            $raw_data = $data['raw_data'];
            $device_id = $data['device_id'];
            $store_no = $data['store_no'];

            $obj = new BaseController();
            $data = [
                'orgId' => $orgId,
                'reqId' => time(),
                'version' => '1.0',
                'timestamp' => date('Ymdhis', time()),
                'signType' => 'RSA',
                'reqData' => [
                    'mno' => $mno, //商户编号
                    'storeNo' => $store_no, //门店编号
                    'orderNo' => $out_trade_no, //商户订单号
                    'rawdata' => $raw_data, //初始数据
                    'deviceId' => $device_id, //微信终端编号（WXtrmno）
                ],
            ];

//            Log::info('随行付-获取微信刷脸调用凭证：');
//            Log::info($data);
            $re = $obj->execute($data, $url, $privateKey, $sxfpublic);
//            Log::info($re);
            //系统错误
            if ($re['status'] == 0) {
                return $re;
            }

            //业务成功
            if ($re['data']['code'] == "0000") {
                //成功
                if ($re['data']['respData']['bizCode'] == "0000") {
                    return [
                        'status' => 1,
                        'message' => '交易成功',
                        'data' => $re['data']
                    ];
                } else {
                    return [
                        'status' => 0,
                        'message' => $re['data']['respData']['bizMsg']
                    ];
                }
            } else {
                return [
                    'status' => 0,
                    'message' => $re['data']['msg']
                ];
            }
        } catch (\Exception $ex) {
            return [
                'status' => '0',
                'message' => $ex->getMessage().' | '.$ex->getFile().' | '.$ex->getLine()
            ];
        }
    }


}
